// 引入connect用于链接UI组件与redux
import {connect} from "react-redux"
// 引入Count的UI组件
import CountUI from '../../components/Count'
// 引入action
import {createIncrementAction, createDecrementAction, createIncrementAsyncAction} from '../../redux/count_actions'

// connect()()创建并暴露一个Count组件
export default connect(
    state => ({count:state}), 
    // mapDispatchToProps的一般写法
    /*dispatch => ({
            jia:(number)=>{
                // 通知redux执行加法
                dispatch(createIncrementAction(number))
            },
            jian:(number)=>{
                // 通知redux执行减法
                dispatch(createDecrementAction(number))
            },
            jiaAsync:(number, time)=>{
                // 通知redux异步执行加法
                dispatch(createIncrementAsyncAction(number, time))
            }, 
        }) */

    // mapDispatchToProps的简写
    {
        // 因为react-redux可以自动的进行分发
        jia:createIncrementAction,
        jian:createDecrementAction,
        jiaAsync:createIncrementAsyncAction,
    }
)(CountUI)

